import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
import Confirm from '#cpt/temp/Confirm'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const PreviewAuditReport 	= $Lazy.file(()=>import('@views/_public/preview-audit-report/js/utils'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		selectedRows:[],
		// 搜索表单列表
		forms : [
			{ label: '标本条码',		name: 'spec_code' },
			{ label: '终止时间',  	names: ['start_date','end_date'], type:'date-range',format:1},
		]
	}
	
	model = {}
	
	componentDidMount(){
		if(window.isInit){
			this.fetch()
		}
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'sp-info-modify/abortList',{isIndex:true})
	
	// 表单
	cols = [
		{ title: '标本条码',			dataIndex: 'spec_code', 		...$fn.table.spec_code },
		{ title: '姓名', 			dataIndex: 'patient_name', 		...$fn.table.name },
		{ title: '医院', 			dataIndex: 'hosp_name', 		width:300 },
		{ title: '终止时间', 		dataIndex: 'created_at', 		...$fn.table.time },
	]
	// 操作按钮
	controls = () => {
		const { selectedRows } = this.state
		let arr = []
		selectedRows.forEach((v,i)=>{
			arr.push(v.uuid) 
		})
		return [
			Confirm.call(this, '批准报告单', 'sp-info-modify/approve', { isKeys:1, query:{uuid:arr}}),
			Controls.click.call(this, '预览并批准报告单', () => {
				const { spec_num, ts_id, project_id } = selectedRows[selectedRows.length - 1]
				PreviewAuditReport.then(f => f.call(this,{ spec_num, uuid:ts_id, project_id, root:'service-system/report-termination-log' }))
			}, { isKeys:1 })
		]
	}

	render(){
		return (
			<Page title='报告单终止记录' controls={this.controls()}>
				{/* 搜索 */}
				{ SearchForm.call(this) }
				{/* 表格 */}
				{ Table.call(this,{isIndex:true, isInit: window.isInit}) }
			</Page>
		)
	}
}

export default Index